using micromsg;
using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Protocol;
using MicroMsg.Scene;
using MicroMsg.Storage;
using System;
namespace MicroMsg.Plugin.Sns.Scene
{
	public class NetSceneSnsTimeLine : NetSceneBaseEx<SnsTimeLineRequest, SnsTimeLineResponse, SnsTimeLineRequest.Builder>
	{
		private const string TAG = "NetSceneSnsTimeLine";
		private static NetSceneSnsTimeLine _mInstance;
		private SnsTimeLineCallBack onTimeLineRsp;
		public static NetSceneSnsTimeLine Instance
		{
			get
			{
				if (NetSceneSnsTimeLine._mInstance == null)
				{
					NetSceneSnsTimeLine._mInstance = new NetSceneSnsTimeLine();
				}
				return NetSceneSnsTimeLine._mInstance;
			}
		}
		public NetSceneSnsTimeLine()
		{
		}
		public NetSceneSnsTimeLine(SnsTimeLineCallBack snsTimeLineCallBack_0)
		{
			this.onTimeLineRsp = snsTimeLineCallBack_0;
		}
		public bool getFirstPage(string strFirstPageMd5 = null)
		{
			base.beginBuilder();
			this.mBuilder.BaseRequest = NetSceneBase.makeBaseRequest(0);
			this.mBuilder.FirstPageMd5 = ((strFirstPageMd5 == null) ? "" : strFirstPageMd5);
			this.mBuilder.MaxId = 0uL;
			this.mBuilder.MinFilterId = 0uL;
			this.mBuilder.LastRequestTime = 0u;
			this.mSessionPack.mCmdID = 98;
			base.endBuilder();
			return true;
		}
		public bool getNextPage(ulong maxID, ulong minID = 0uL, uint LastRequestTime = 0u)
		{
			base.beginBuilder();
			this.mBuilder.BaseRequest = NetSceneBase.makeBaseRequest(0);
			this.mBuilder.MaxId = maxID;
			this.mBuilder.MinFilterId = minID;
			this.mBuilder.LastRequestTime = LastRequestTime;
			this.mBuilder.FirstPageMd5 = "";
			this.mSessionPack.mCmdID = 98;
			base.endBuilder();
			return true;
		}
		public bool doScene(bool isFirstPage, ulong lastID)
		{
			base.beginBuilder();
			this.mBuilder.BaseRequest = NetSceneBase.makeBaseRequest(0);
			if (isFirstPage)
			{
				SnsPage snsPage = StorageMgr.snsPage.method_1(AccountMgr.strUsrName);
				if (snsPage == null)
				{
					this.mBuilder.FirstPageMd5 = "";
					this.mBuilder.MaxId = 0uL;
				}
				else
				{
					this.mBuilder.FirstPageMd5 = snsPage.strFirstPageMd5;
					this.mBuilder.MaxId = 0uL;
				}
			}
			else
			{
				this.mBuilder.FirstPageMd5 = "";
				this.mBuilder.MaxId = lastID;
			}
			this.mBuilder.MinFilterId = 0uL;
			this.mBuilder.LastRequestTime = 0u;
			this.mSessionPack.mCmdID = 98;
			base.endBuilder();
			return true;
		}
		protected override void onFailed(SnsTimeLineRequest request, SnsTimeLineResponse response)
		{
			Log.smethod_1("NetSceneSnsTimeLine", "send request failed");
			if (this.onTimeLineRsp != null)
			{
				this.onTimeLineRsp(-1, null);
			}
			EventCenter.postEvent(EventConst.ON_NETSCENE_SNS_TIME_LINE_ERR, RetConst.MM_ERR_CLIENT, null);
		}
		protected override void onSuccess(SnsTimeLineRequest request, SnsTimeLineResponse response)
		{
			SnsRetCode ret = (SnsRetCode)response.BaseResponse.Ret;
			if (ret != SnsRetCode.MMSNS_MM_OK && ret != SnsRetCode.MMSNS_RET_ISALL)
			{
				Log.smethod_1("NetSceneSnsTimeLine", "send request failed ret =" + ret);
				EventCenter.postEvent(EventConst.ON_NETSCENE_SNS_TIME_LINE_ERR, ret, null);
				if (this.onTimeLineRsp != null)
				{
					this.onTimeLineRsp(-1, null);
				}
				return;
			}
			if (this.onTimeLineRsp != null)
			{
				this.onTimeLineRsp((int)ret, response);
			}
			if (response.ObjectListList.get_Count() == 0)
			{
				return;
			}
			EventCenter.postEvent(EventConst.ON_NETSCENE_SNS_TIME_LINE_SUCCESS, ret, null);
		}
	}
}
